<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/common/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="${path}/static/common/layui/css/layui.css"/>
</head>
<body>
	<form id="form" class="layui-form layui-form-pane" action="">
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="username" autocomplete="off" placeholder="请输入用户名" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户密码</label>
	    <div class="layui-input-block">
	      <input type="text" name="password" lay-verify="required" placeholder="请输入用户密码" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">邮箱</label>
	    <div class="layui-input-block">
	      <input type="text" name="email" lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">电话</label>
	    <div class="layui-input-block">
	      <input type="text" name="phone" lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">找回密码问题</label>
	    <div class="layui-input-block">
	      <input type="text" name="question" lay-verify="required" placeholder="请输入找回密码问题" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">找回密码答案</label>
	    <div class="layui-input-block">
	      <input type="text" name="answer" lay-verify="required" placeholder="请输入找回密码答案" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item" pane="">
	    <label class="layui-form-label">角色</label>
	    <div class="layui-input-block">
	      <input type="radio" name="role" value="0" title="管理员" checked="">
	      <input type="radio" name="role" value="1" title="普通用户">
	    </div>
	  </div>
	</form>
	<button class="layui-btn" onclick="submitForm()">添加</button>
	
	
	
	<script src="${path}/static/common/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use(['form'], function(){
			var form = layui.form;
		});
		 
		function submitForm() {
			$.post(
				"${path}/user/insert.action",
				$("#form").serialize(),
				function(result) {
					console.log(result);
					if(result.success) {
						mylayer.successMsg(result.msg);
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
						var index = parent.layer.getFrameIndex(window.name);
						// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
						setTimeout(function() {
							 // 关闭弹出层
							 parent.layer.close(index); 
							 // 刷新父页面
							 window.parent.location.reload();
						}, 1000);
					} else {
						mylayer.errorMsg(result.msg);
					}
				},
				"json"
			);
			
		}
	</script>
</body>
</html>